<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
require_once 'Base/BaseMenu.class.php';

Class Menu {

	public function  __construct() {
			if( true == isset( $_SERVER['connection'] ) ) {
				$this->connection = $_SERVER['connection'];
			}
	}

	
	/*******************************************************************************************
	******************************** Fetch Functions *******************************************
	*******************************************************************************************/

	public function fetchSql( $strSql ) {
		$result = $this->connection->RunQuery( $strSql );
		$arrobjMenu = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objMenu = new BaseMenu();
			$objMenu->setMid( ( true == isset( $row["mid"] ) ) ? $row["mid"] : 'NULL' );
			$objMenu->setTitle( ( true == isset( $row["title"] ) ) ? $row["title"] : 'NULL' );
			$objMenu->setPath( ( true == isset( $row["path"] ) ) ? $row["path"] : 'NULL' );
			$objMenu->setImgPath( ( true == isset( $row["img_path"] ) ) ? $row["img_path"] : 'NULL' );
			$objMenu->setParent( ( true == isset( $row["parent"] ) ) ? $row["parent"] : 'NULL' );
			$objMenu->setRank( ( true == isset( $row["rank"] ) ) ? $row["rank"] : 'NULL' );
			$objMenu->setDummy( ( true == isset( $row["dummy"] ) ) ? $row["dummy"] : 'NULL' );
			array_push( $arrobjMenu, $objMenu );
		}
		return $arrobjMenu;
	}
	public function fetchAllMenu() {
		$result = $this->connection->RunQuery("SELECT * FROM MENU");
		$arrobjMenu = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objMenu = new BaseMenu();
			$objMenu->setMid( ( true == isset( $row["mid"] ) ) ? $row["mid"] : 'NULL' );
			$objMenu->setTitle( ( true == isset( $row["title"] ) ) ? $row["title"] : 'NULL' );
			$objMenu->setPath( ( true == isset( $row["path"] ) ) ? $row["path"] : 'NULL' );
			$objMenu->setImgPath( ( true == isset( $row["img_path"] ) ) ? $row["img_path"] : 'NULL' );
			$objMenu->setParent( ( true == isset( $row["parent"] ) ) ? $row["parent"] : 'NULL' );
			$objMenu->setRank( ( true == isset( $row["rank"] ) ) ? $row["rank"] : 'NULL' );
			$objMenu->setDummy( ( true == isset( $row["dummy"] ) ) ? $row["dummy"] : 'NULL' );
			array_push( $arrobjMenu, $objMenu);
		}
		return $arrobjMenu;
	}
	public function fetchAllMenuByIds( $arrintIds ) {
		$result = $this->connection->RunQuery("SELECT * FROM MENU WHERE id IN ( implode( "," $arrintIds ) " );
		$arrobjMenu = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objMenu->setMid( ( true == isset( $row["mid"] ) ) ? $row["mid"] : 'NULL' );
			$objMenu->setTitle( ( true == isset( $row["title"] ) ) ? $row["title"] : 'NULL' );
			$objMenu->setPath( ( true == isset( $row["path"] ) ) ? $row["path"] : 'NULL' );
			$objMenu->setImgPath( ( true == isset( $row["img_path"] ) ) ? $row["img_path"] : 'NULL' );
			$objMenu->setParent( ( true == isset( $row["parent"] ) ) ? $row["parent"] : 'NULL' );
			$objMenu->setRank( ( true == isset( $row["rank"] ) ) ? $row["rank"] : 'NULL' );
			$objMenu->setDummy( ( true == isset( $row["dummy"] ) ) ? $row["dummy"] : 'NULL' );
			array_push( $arrobjMenu, $objMenu );
		}
		return $arrobjMenu;
	}

	public function fetchMenuById( $intId ) {
		$result = $this->connection->RunQuery( "SELECT * FROM MENU WHERE id = " . $intId );
			$objMenu = NULL;
		while($row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objMenu = new BaseMenu();
			$objMenu->setMid( ( true == isset( $row["mid"] ) ) ? $row["mid"] : 'NULL' );
			$objMenu->setTitle( ( true == isset( $row["title"] ) ) ? $row["title"] : 'NULL' );
			$objMenu->setPath( ( true == isset( $row["path"] ) ) ? $row["path"] : 'NULL' );
			$objMenu->setImgPath( ( true == isset( $row["img_path"] ) ) ? $row["img_path"] : 'NULL' );
			$objMenu->setParent( ( true == isset( $row["parent"] ) ) ? $row["parent"] : 'NULL' );
			$objMenu->setRank( ( true == isset( $row["rank"] ) ) ? $row["rank"] : 'NULL' );
			$objMenu->setDummy( ( true == isset( $row["dummy"] ) ) ? $row["dummy"] : 'NULL' );
		}
		return $objMenu;
	}

	public function GetKeysOrderBy($column, $order){
		$keys = array(); $i = 0;
		$result = $this->connection->RunQuery("SELECT mid from menu order by $column $order");
			while($row = $result->fetch_array(MYSQLI_ASSOC)){
				$keys[$i] = $row["mid"];
				$i++;
			}
	return $keys;
	}

	public function endMenu(){
		$this->connection->CloseMysql();
	}

}